package com.wnxy.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wnxy.admin.dto.JChargingCardDto;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wnxy.admin.entity.ChargingCard;
import com.wnxy.admin.mapper.ChargingCardMapper;
import com.wnxy.admin.service.IChargingCardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 充电卡 服务实现类
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@Service
public class ChargingCardServiceImpl extends ServiceImpl<ChargingCardMapper, ChargingCard> implements IChargingCardService {

    private final ChargingCardMapper chargingCardMapper;
    public ChargingCardServiceImpl(ChargingCardMapper chargingCardMapper){
        this.chargingCardMapper = chargingCardMapper;
    }


    /*
     * #ChargingCard充电卡实体[订单业务]
     * @chargingStationId绑定状态修改接口
     * */
    @Override
    public void editChargingStationId(Integer customerId, Long chargingStationId) {
        ChargingCard chargingCard = chargingCardMapper.selectOne(Wrappers.lambdaQuery(ChargingCard.class)
                .eq(ChargingCard::getCustomerId, customerId));
        chargingCardMapper.update(chargingCard, Wrappers.lambdaUpdate(ChargingCard.class)
                .set(ChargingCard::getChargingStationId, chargingStationId)
                .eq(ChargingCard::getId, chargingCard.getId()));
    }

    @Override
    public PageInfo<JChargingCardDto> findByPage(String name, int pageNum, int pageSize) {
        //1.设置页码和每页大小
        PageHelper.startPage(pageNum, pageSize);
        //2.调用DAO层查询
        List<JChargingCardDto> list = chargingCardMapper.findAll(name);
        //3.返回PageInfo对象
        return new PageInfo<>(list);
    }
    /*
     * @queryChargingCardDetail 查询chargingCard详情
     * */
    @Override
    public ChargingCard queryChargingCardDetail(Long cardId) {
        ChargingCard chargingCard = chargingCardMapper.selectOne(Wrappers
                .lambdaQuery(ChargingCard.class)
                .eq(ChargingCard::getId, cardId));
        return chargingCard;
    }
}
